﻿using IEntities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;

namespace IRepository
{
    public interface IBaseRepository<TEntity> where TEntity : class,IEntity
    {
        //增
        TEntity Insert(TEntity entity);
        object InsertAndGetID(TEntity entity);
        Task<TEntity> InsertAsync(TEntity entity);
        Task<object> InsertAndGetIDAsync(TEntity entity);

        //删
        bool Delete(TEntity entity);
        bool Deletes(dynamic[] ids);
        bool DeleteByID(object id);
        Task DeleteAsync(TEntity entity);
        Task DeletesAsync(dynamic[] ids);
        Task DeleteByIDAsync(object id);

        //改
        TEntity Update(TEntity entity);
        object UpdateAndGetID(TEntity entity);
        List<TEntity> Updates(List<TEntity> entities);
        Task<TEntity> UpdateAsync(TEntity entity);
        Task<object> UpdateAndGetIDAsync(TEntity entity);
        Task<List<TEntity>> UpdatesAsync(List<TEntity> entities);

        //查
        TEntity Find(Expression<Func<TEntity, bool>> whereExpression);
        TEntity FindByID(object id);
        List<TEntity> Query(Expression<Func<TEntity, bool>> whereExpression);
        List<TEntity> QueryPage(Expression<Func<TEntity, bool>> whereExpression, int pageIndex = 1, int pageSize = 10,int pageCount=10);
        Task<TEntity> FindAsync(Expression<Func<TEntity, bool>> whereExpression);
        Task<TEntity> FindByIDAsync(object id);
        Task<List<TEntity>> QueryAsync(Expression<Func<TEntity, bool>> whereExpression);
        Task<List<TEntity>> QueryPageAsync(Expression<Func<TEntity, bool>> whereExpression, int pageIndex = 1, int pageSize = 10,int pageCount=10);

        //其他
        object[] Test();
        int Count();
        int Count(Expression<Func<TEntity, bool>> whereExpression);
        TEntity Get(object id);
        TEntity Get(Expression<Func<TEntity, bool>> whereExpression);
        TEntity FirstOrDefault(object id);
        TEntity FirstOrDefault(Expression<Func<TEntity, bool>> whereExpression);
        List<TEntity> GetAllList();
        List<TEntity> GetAllList(Expression<Func<TEntity, bool>> whereExpression);
        Task<int> CountAsync();
        Task<int> CountAsync(Expression<Func<TEntity, bool>> whereExpression);
        Task<TEntity> GetAsync(object id);
        Task<TEntity> GetAsync(Expression<Func<TEntity, bool>> whereExpression);
        Task<TEntity> FirstOrDefaultAsync(object id);
        Task<TEntity> FirstOrDefaultAsync(Expression<Func<TEntity, bool>> whereExpression);
        Task<List<TEntity>> GetAllListAsync();
        Task<List<TEntity>> GetAllListAsync(Expression<Func<TEntity, bool>> whereExpression);
    }
}
